#!/bin/bash

import os
import time
import datetime

'''
备份数据库
'''
dbHost = '175.102.1.150'
dbUser = 'root'
dbPass = 'root'
dbName = 'www.jgy.pro'
# backupDir = r'/data/backup'
backupDir = r'/Users/Mac/Desktop/backup'
createTime = time.strftime('%Y%m%d')

def createDir():
    if not os.path.exists(backupDir):
        os.makedirs(backupDir)
    pass
createDir()

# dumpcmd = "mysqldump -u " + DB_USER + " -p" + DB_USER_PASSWORD + " " + db + " > " + Dir_backup + "/" + db + ".sql"
dumpcmd = "mysqldump -u{0} -p{1} {2} > {3}/{4}-{2}.sql".format(dbUser,dbPass,dbName,backupDir,createTime)
print(dumpcmd)
os.system(dumpcmd)
print('{} > database backup success.'.format(dbName))
